<?php

namespace App\Models;

use App\Services\CommonService;
use App\Services\EducationService;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Testing\Fluent\Concerns\Has;

class TwoElements extends Model
{
     use HasFactory;
    protected $table = 'sp_order_two_elements';
    protected $primaryKey = 'id';
    public $timestamps = false;

    //查询地区信息
    public static  function getOrderAll($order_id)
    {
        $data = (new self())::where('order_id',$order_id)
            ->get();
        $data = $data ? $data->toArray() : array();
        foreach ($data as $k=>$v){
            if($v['result_code']==1){
                $data[$k]['result2'].='(查询成功有结果)';
                if($v['result_code']==1){
                    $data[$k]['result2'].='(常用联系人)';
                }else{
                    $data[$k]['result2'].='(非常用联系人)';
                }

            }else if($v['result_code']===0){
                $data[$k]['result2']='(查询成功无结果)';
            }else{
                $data[$k]['result2']='';
            }
        }
        return $data;
    }

    public function insertCheckPhone($order_id,$phone,$name)
    {

        if(!Verify_Phone($phone)){
            return ReturnMsg(CommonService::HTTP_CODE_FAIL, '手机号码有误');
        }
        $res= $this
            ->where('order_id',$order_id)
            ->where('phone',$phone)
            ->value('id');
        if($res){
            return ReturnMsg(CommonService::HTTP_CODE_FAIL, '此手机号码已查询');
        }

        $data=['order_id'=>$order_id,'phone'=>$phone,'name'=>$name];
        $res=EducationService::queryTwoName($request);
        if($res['code']=='0'){
            $data['result']=$data['data'];
            return $this::insert($data);
        }else{
            return ReturnMsg(CommonService::HTTP_CODE_FAIL, $res['message']);
        }
    }



}
